const {
  byessay,
  reply,
  deletecom,
  thumb,
  byuser,
  mangetbyessay,
} = require("../services/comment.services");
class CommentController {
  //根据文章查询所有评论
  async byessay(ctx, next) {
    const { id } = ctx.request.params;
    try {
      const result = await byessay(id);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
  //回复评论
  async reply(ctx, next) {
    try {
      const result = await reply(ctx.request.body);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
  //删除评论
  async deletecom(ctx, next) {
    const { id } = ctx.request.params;
    try {
      const result = await deletecom(id);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
  //点赞评论或取消点赞
  async thumb(ctx, next) {
    const body = ctx.request.body;
    try {
      const result = await thumb(body);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
  //根据用户id查询评论
  async byuser(ctx) {
    const { id } = ctx.request.params;
    try {
      const result = await byuser(id);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
  //管理员根据文章id查询评论
  async mangetbyessay(ctx) {
    const id = ctx.request.params.id;
    try {
      const result = await mangetbyessay(id);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
}
module.exports = new CommentController();
